<?php
/**
 * @file   migrate data from oracle to redis
 * @author huangqingyun@snda.com
 */
error_reporting(E_ALL);

if (!isset($argv) || count($argv) <= 0) {
    exit("no access via internet!");
}

#设置默认时区
date_default_timezone_set ('Asia/Shanghai');
ini_set('oci8.max_persistent', 10);
ini_set('oci8.persistent_timeout', 100);
ini_set('oci8.ping_interval', 60);
require dirname(__FILE__) . '/config/config.conf.php';
require dirname(__FILE__) . '/libraries/Ku6AnalyiticsModel.php';

$logger = getLogger();
$anaModel = new Ku6AnalyiticsModel(TRUE);
if ($anaModel->getErrNo()) {
    echo "connect to oracle failed\n";

    //$return['code'] = $anaModel->getErrNo();
    $code = $anaModel->getErrNo();
	$err = Ku6ErrorCode::getErrMsg($code);

    $logger->log($err, PEAR_LOG_EMERG);
    exit;
}

$g_inmigrate = TRUE;      //在同步模式, 读写db的次序与web请求处理模式相反
$g_specified  = FALSE;    //指定同步某库
$g_migratedb = 0;

if (sizeof($argv) == 2) {
    $g_specified = TRUE;
    $g_migratedb = (int) $argv[1];
}

echo "start to migrate\n";
$ret = $anaModel->migrateDbToRedis();
if ($ret === FALSE) {
    echo "migration failed";

    $logger->log('migrate orace data to redis failed', PEAR_LOG_EMERG);
    exit;
}

echo "migrated successfully!\n";

